<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>历史成交记录</title>
<link rel="styleSheet" href="../../css/bootstrap.min.css"> 
<style type="text/css">
	#tableDiv{
		margin-left: 60px;
		margin-top: 80px;
		width: 1000px;
	}
	#fenyeDiv{
		margin-left:60px;
		margin-top:0px;
		width: 1000px;
		text-align: center;
	}
	
	#noticeDiv{
		margin-left: 60px;
		margin-top: 10px;
		width: 1000px;
		text-align: center;
	}
	#fenyeDiv{
		position: absolute;
		top:330px;
		left:-100px;
	}
	td{
		text-align: center;
	}
</style>
</head>
<body style="background-color: transparent;">
	<div id="tableDiv">
	<p><input type="hidden" id="ladyID" value="${sessionScope.myLandLady.ladyID }"></p>
		<table id="historyTable" class="table table-striped table table-bordered" >
			<tr>
			<td>编号</td>
			<td>出租车位</td>
			<td>开始时间</td>
			<td>结束时间</td>
			<td>抢租客</td>
			<td>操作</td>
			</tr>
		</table>
	</div>
	<div id="fenyeDiv" class="fenyeDiv">
		<ul class="pager">
			<li><a href="javascript:void(0)" id="firstPage">首页</a></li>
			<li><a href="javascript:void(0)" id="pageUp">前一页</a></li>
			<li><label id="currentPage"></label><label>/</label><label
				id="pageCount"></label></li>
			<li><a href="javascript:void(0)" id="pageDown">下一页</a></li>
			<li><a href="javascript:void(0)" id="lastPage">末页</a>跳转至<input style="width:50px;" id="pagess" name="page" type="text" size="2"  maxlength="2" value="1" onkeyup='this.value=this.value.replace(/\D/gi,"")'>页</li>
			<li><a href="javascript:void(0)" id="forPage">跳转</a></li>
	</ul>
	</div>
	<div id="noticeDiv">
		<label id="notice" style="color:red;"></label>
	</div>
</body>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
	$(function(){
		init();
	})
	function init(){
		showAllHistory(1);
	}
	function showAllHistory(curPage){
		var tr="";
		var ladyID = $("#ladyID").val();
		$.ajax({
			url:"showAllHistory.do",
			type:"post",
			data:{"ladyID":ladyID,"curPage":curPage},
			async:true,
			success:function(msg){
				for (var i = 0; i < msg.list.length; i++) {
					var index = new Number(i+1);
					var startTime =new Date(msg.list[i].purpose.rentInfo.startTime); 
					var endTime = new Date(msg.list[i].purpose.rentInfo.endTime);
					var timestamp = Date.parse(new Date());
					tr+="<tr><td>"+index+"</td><td>"+msg.list[i].purpose.rentInfo.personalcarport.carportAddress+msg.list[i].purpose.rentInfo.personalcarport.carNO+"</td>"
					+"<td>"+startTime.getFullYear()+"年"+(startTime.getUTCMonth()+1)+"月"+(startTime.getUTCDate()+1)+"日"+startTime.getHours()+"时"+"</td>"
					+"<td>"+endTime.getFullYear()+"年"+(endTime.getUTCMonth()+1)+"月"+(endTime.getUTCDate()+1)+"日"+endTime.getHours()+"时"+"</td>"
					+"<td>"+msg.list[i].purpose.renter.renterName+"</td>"
					if(timestamp<endTime){
						tr+="<td><button disabled='disabled' class='complaint btn btn-danger' id = '"+msg.list[i].recordID+"'>投诉</button></td></tr>"
					}else{
						tr+="<td><button class='complaint btn btn-danger' id = '"+msg.list[i].recordID+"'>投诉</button></td></tr>"
					}			
				}
				if(msg.list.length==0){
					$("#currentPage").html("0");
					$("#pageCount").html("0");
				}
				else{
					$("#currentPage").html(msg.curPage);
					$("#pageCount").html(msg.countPage);
				}
				$("#historyTable").append(tr);
			}
		})
	}
$(".pager a").click	(function(){
	var curPage=$("#currentPage").html();
	var countPage=$("#pageCount").html();
	var pageFtn=$(this).html();
	
	if(pageFtn=="首页"){
		curPage=1;
	}
	if(pageFtn=="前一页"){
		
		curPage=parseInt(curPage)-1;
		if(curPage<1){
			curPage=1;
		}
	}
	if(pageFtn=="下一页"){
		
		curPage=parseInt(curPage)+1;
		if(curPage>countPage){
			curPage=countPage;
		}
	}
	if(pageFtn=="末页"){
		
		curPage=countPage;
	}
	if(pageFtn=="跳转"){
		
		var pagger=$("#pagess").val();
		if(pagger>countPage){
			curPage=countPage;
			$("#pagess").val(countPage);
		}else if(pagger<1){
			curPage=1;
			$("#pagess").val("1");
		}else if(pagger==""){
			curPage=1;
			$("#pagess").val("1");
		}else{
			curPage=pagger;
		}
	}
	$("#historyTable tr:gt(0)").remove();
	$("#currentPage").html(curPage);
	
	showAllHistory(curPage);
		
	});
	$(".complaint").live("click",function(){
		var recordID = $(this).attr("id");
		$.ajax({
			url:"checkIsComplaint.do",
			type:"post",
			async:true,
			data:{"recordID":recordID},
			success:function(msg){
				if(msg==1){
					$("#notice").html("已经投诉过,无法重复投诉！")
				}else{
					window.location.href="ladyComplaint.jsp?id="+recordID;
				}				
			}
		})
		
		$(this).blur(function(){
			$("#notice").html("");
		})
		
		
	})
</script>
</html>